package com.lengtouzai.databaseexp.entity;

import io.jmix.core.MetadataTools;
import io.jmix.core.entity.annotation.JmixGeneratedValue;
import io.jmix.core.metamodel.annotation.DependsOnProperties;
import io.jmix.core.metamodel.annotation.InstanceName;
import io.jmix.core.metamodel.annotation.JmixEntity;
import jakarta.persistence.*;

import java.time.LocalDate;
import java.util.UUID;

@JmixEntity
@Table(name = "EXP_EDUCATIONAL_EXPERIENCE", indexes = {
        @Index(name = "IDX_EXP_EDUCATIONAL_EXPERIENCE_USER", columnList = "USER_ID")
})
@Entity(name = "exp_EducationalExperience")
public class EducationalExperience {
    @JmixGeneratedValue
    @Column(name = "ID", nullable = false)
    @Id
    private UUID id;

    @Column(name = "VERSION", nullable = false)
    @Version
    private Integer version;

    @Column(name = "LEVEL_")
    private String level;

    @Column(name = "START_TIME")
    private LocalDate startTime;

    @Column(name = "END_TIME")
    private LocalDate endTime;

    @Column(name = "SCHOOL")
    private String school;

    @Column(name = "DEGREE")
    private String degree;

    @JoinColumn(name = "USER_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private User user;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getDegree() {
        return degree;
    }

    public void setDegree(String degree) {
        this.degree = degree;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public LocalDate getEndTime() {
        return endTime;
    }

    public void setEndTime(LocalDate endTime) {
        this.endTime = endTime;
    }

    public LocalDate getStartTime() {
        return startTime;
    }

    public void setStartTime(LocalDate startTime) {
        this.startTime = startTime;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    @InstanceName
    @DependsOnProperties({"school", "degree"})
    public String getInstanceName(MetadataTools metadataTools) {
        return String.format("%s - %s",
                metadataTools.format(school),
                metadataTools.format(degree));
    }
}